package vip.xiaonuo.supplier.modular.custom.objects.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.supplier.modular.custom.objects.entity.SupplierObjects;
import vip.xiaonuo.supplier.modular.custom.objects.param.SupplierObjectsAddParam;
import vip.xiaonuo.supplier.modular.custom.objects.param.SupplierObjectsEditParam;
import vip.xiaonuo.supplier.modular.custom.objects.param.SupplierObjectsIdParam;
import vip.xiaonuo.supplier.modular.custom.objects.param.SupplierObjectsPageParam;
import vip.xiaonuo.supplier.modular.custom.objects.service.SupplierObjectsService;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import java.util.List;

/**
 * 业务对象控制器
 *
 * @author Mr.wu
 * @date  2025/04/19 11:37
 */
@Tag(name = "业务对象控制器")
@RestController
@Validated
public class SupplierObjectsController {

    @Resource
    private SupplierObjectsService supplierObjectsService;

    /**
     * 获取业务对象分页
     *
     * @author Mr.wu
     * @date  2025/04/19 11:37
     */
    @Operation(summary = "获取业务对象分页")
    @SaCheckPermission("/supplier/custom/objects/page")
    @GetMapping("/supplier/custom/objects/page")
    public CommonResult<Page<SupplierObjects>> page(SupplierObjectsPageParam supplierObjectsPageParam) {
        return CommonResult.data(supplierObjectsService.page(supplierObjectsPageParam));
    }

    /**
     * 添加业务对象
     *
     * @author Mr.wu
     * @date  2025/04/19 11:37
     */
    @Operation(summary = "添加业务对象")
    @CommonLog("添加业务对象")
    @SaCheckPermission("/supplier/custom/objects/add")
    @PostMapping("/supplier/custom/objects/add")
    public CommonResult<String> add(@RequestBody @Valid SupplierObjectsAddParam supplierObjectsAddParam) {
        supplierObjectsService.add(supplierObjectsAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑业务对象
     *
     * @author Mr.wu
     * @date  2025/04/19 11:37
     */
    @Operation(summary = "编辑业务对象")
    @CommonLog("编辑业务对象")
    @SaCheckPermission("/supplier/custom/objects/edit")
    @PostMapping("/supplier/custom/objects/edit")
    public CommonResult<String> edit(@RequestBody @Valid SupplierObjectsEditParam supplierObjectsEditParam) {
        supplierObjectsService.edit(supplierObjectsEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除业务对象
     *
     * @author Mr.wu
     * @date  2025/04/19 11:37
     */
    @Operation(summary = "删除业务对象")
    @CommonLog("删除业务对象")
    @SaCheckPermission("/supplier/custom/objects/delete")
    @PostMapping("/supplier/custom/objects/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                                   List<SupplierObjectsIdParam> supplierObjectsIdParamList) {
        supplierObjectsService.delete(supplierObjectsIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取业务对象详情
     *
     * @author Mr.wu
     * @date  2025/04/19 11:37
     */
    @Operation(summary = "获取业务对象详情")
    @SaCheckPermission("/supplier/custom/objects/detail")
    @GetMapping("/supplier/custom/objects/detail")
    public CommonResult<SupplierObjects> detail(@Valid SupplierObjectsIdParam supplierObjectsIdParam) {
        return CommonResult.data(supplierObjectsService.detail(supplierObjectsIdParam));
    }
}
